import Opt from '@/components/dt/info/Opt.js'
import houseOpt from '@/biz/option/house.js'

let _this = null
class SearchOpt extends Opt {
  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        title: '目标年份',
        placeholder: '全部',
        key: 'year',
        date: {
          type: 'year',
          clearable: false,
          disabled: (date) => {
            const disabledDate = date.getFullYear()
            const currentYear = new Date().getFullYear()
            return !(disabledDate >= currentYear - 2 && disabledDate <= currentYear)
          }
        },
        change: (res) => {
          _this.searchInfo.month = '01'
        }
      },
      {
        title: '目标月份',
        placeholder: '全部',
        key: 'month',
        date: {
          type: 'month',
          clearable: false,
          format: 'MM',
          disabled: (date) => {
            const year = _this.searchInfo.year
            const currentYear = new Date().getFullYear()
            return currentYear == year ? date.valueOf() > new Date().getTime() : ''
          }
        }
      },
      houseOpt.create({
        key: 'buildingId',
        visible: _this.fromPage != 'case',
        to: (info) => {
          return {
            buildingId: info.housesId
          }
        }
      })
    ]
  }
}

export default SearchOpt
